package person.bing.fbcloud.common.core.util;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import person.bing.fbcloud.common.core.constant.CommonConstant;
import person.bing.fbcloud.common.core.exception.CheckedException;

/**
 * 全局异常捕捉
 * @Author: mengfanbing
 * @Date: 2019/4/22 11:10
 */
@RestControllerAdvice
public class GlobalExceptionHandlerResolver {

    @ExceptionHandler(Exception.class)
    @ResponseStatus(HttpStatus.OK)
    public R handleException(Exception e){
        e.printStackTrace();
        return R.builder()
                .code(CommonConstant.FAIL)
                .msg("系统异常")
                .build();
    }

    @ExceptionHandler(CheckedException.class)
    @ResponseStatus(HttpStatus.OK)
    public R handleCheckedException(CheckedException e){
        return R.builder()
                .code(CommonConstant.FAIL)
                .msg(e.getMessage())
                .build();
    }


}
